package cn.lzd.mr.case1;

import cn.lzd.mr.PathUtil;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * Created by lzd on 2018/5/31.
 * 求取手机号码上下限及总流量
 */
public class MRDemo {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        String path = MRDemo.class.getResource("/case1/").getPath();

        Configuration configuration = new Configuration();
        PathUtil.handleOutPath(path + "output",configuration);
        Job job = Job.getInstance(configuration);
        job.setJarByClass(MRDemo.class);

        job.setMapperClass(MDemo.class);
        job.setReducerClass(RDemo.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(Bean.class);

        job.setOutputKeyClass(NullWritable.class);
        job.setOutputValueClass(Bean.class);

        //交给5个reduce处理
        job.setPartitionerClass(MyPartition.class);
        job.setNumReduceTasks(5);

        FileInputFormat.setInputPaths(job, new Path(path + "text"));
        FileOutputFormat.setOutputPath(job, new Path(path + "output"));

        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}
